package xyz.o0o0o.demo.AuthorizationServerDemo2.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.oauth2.provider.ClientAlreadyExistsException;
import org.springframework.security.oauth2.provider.ClientDetails;
import org.springframework.security.oauth2.provider.ClientRegistrationException;
import org.springframework.security.oauth2.provider.NoSuchClientException;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;

import xyz.o0o0o.demo.AuthorizationServerDemo2.dao.OAuthClientDetailsDao;
import xyz.o0o0o.demo.AuthorizationServerDemo2.entity.CustomClientDetails;
import xyz.o0o0o.demo.AuthorizationServerDemo2.entity.OAuthClientDetails;
import xyz.o0o0o.demo.AuthorizationServerDemo2.service.CustomJdbcClientDetailsService;

@Service
public class CustomJdbcClientDetailsServiceImpl implements CustomJdbcClientDetailsService {
	
	@Autowired
	private OAuthClientDetailsDao oAuthClientDetailsDao;

	public ClientDetails loadClientByClientId(String clientId) throws ClientRegistrationException {
		System.out.println("CustomJdbcClientDetailsServiceImpl loadClientByClientId");
		System.out.println("clientId :" +clientId);
		OAuthClientDetails details = oAuthClientDetailsDao.select(clientId);
		System.out.println("details:" + JSON.toJSONString(details));	
		return new CustomClientDetails(details);
	}

	public void addClientDetails(ClientDetails clientDetails) throws ClientAlreadyExistsException {
		System.out.println("CustomJdbcClientDetailsServiceImpl addClientDetails");
//		OAuthClientDetails details = new OAuthClientDetails();
//		oAuthClientDetailsDao.insert(details);
	}

	public void updateClientDetails(ClientDetails clientDetails) throws NoSuchClientException {
		System.out.println("CustomJdbcClientDetailsServiceImpl updateClientDetails");

	}

	public void updateClientSecret(String clientId, String secret) throws NoSuchClientException {
		System.out.println("CustomJdbcClientDetailsServiceImpl updateClientSecret");

	}

	public void removeClientDetails(String clientId) throws NoSuchClientException {
		System.out.println("CustomJdbcClientDetailsServiceImpl removeClientDetails");

	}

	public List<ClientDetails> listClientDetails() {
		System.out.println("CustomJdbcClientDetailsServiceImpl listClientDetails");
		return null;
	}

}
